<template>
  <div>
    <div id="pullrefresh" class="mui-content">
      <div class="at_list" v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" infinite-scroll-distance="3">
        <!-- <scroller class="scroller" :on-infinite="infinite"
      :on-refresh='refresh' ref='myscroller' :refreshText="refreshText"
      > -->
        <ul class="mui-table-view-chevron" id="inner">
            <div class="news">
              <div>
                <div v-for="(li,index) in activityList" :key="index" @click="toDetail(li.aid)" class="todeList">
                  <div class="small">
                    <div
                      class="leftPic"
                      :style="{background: 'url(https://weyouth.vip/'+ li.photo + ')'}"
                    ></div>
                  </div>
                  <div class="rightFont">
                    <div class="title fontWeight">{{li.title}}</div>
                    <div class="title lineHeight colorGrey">
                      <span>{{li.society}}</span>
                      <a class="last colorGrey">剩余席位{{li.limit}}</a>
                    </div>
                    <div class="title colorGrey">
                      <span class="backGrey">{{li.start_time | formatDate}}</span>
                      <span class="backGrey">{{li.type}}</span>
                      <span class="backGrey">{{li.cost}}</span>
                    </div>
                    <div class="title position">
                      <span class="maplog"></span>
                      {{li.address}}
                    </div>
                  </div>
                  <div class="line"></div>
                </div>
              </div>
            </div>
        </ul>
        <!-- </scroller> -->
      </div>
      <div id="add" class="pic" @click="toAdd" v-show="showAdd">
      </div>
    </div>
  </div>
</template>

<script>
import { getActivityList } from '@/api/society'

export default {
  name: 'ActivityList',
  data () {
    return {
      refreshText: '正在加载...',
      activityList: [],
      page: 1,
      finalPage: 1,
      showAdd: true,
      busy: false,
      listLoading: false
    }
  },
  filters: {
    formatDate: function (value) {
      // return value
      if (value !== '' && value !== null) {
        return value.slice(5, 10).replace('-', '月') + '日'
      }
    }
  },
  created () {
    this.loadList(1)
    if (!this.$route.query.sid) {
      this.showAdd = false
    }
  },
  methods: {
    loadMore () {
      if (this.finalPage >= this.page) {
        this.busy = true
        console.log(123123)
        this.page++
        this.loadList(this.page)
        setTimeout(() => {
        // 这里请求接口去拿数据，实际应该是调用一个请求数据的方法
          this.busy = false
          console.log(454545)
        }, 1000)
      } else {
        this.finalPage = false
      }
    },
    loadList (page) {
      getActivityList({
        page: page,
        sid: this.$route.query.sid
      }).then(res => {
        var resData = res.data.data
        this.finalPage = res.data.last_page
        this.activityList = this.activityList.concat(resData)
      }).catch(err => {
        console.log(err)
      })
    },
    toDetail (aid) {
      var param = (window.location.hash).split('#')[1]
      if (param === 'sms') {
        this.$router.push('/send_sms?aid=' + aid + '&sid=' + this.$route.query.sid)
      } else if (param === 'email_activity') {
        this.$router.push('/send_email?aid=' + aid + '#email_activity')
      } else {
        this.$router.push('/activity_details?aid=' + aid)
      }
    },
    toAdd () {
      this.$router.push('/add_activity?sid=' + this.$route.query.sid)
    }
  }
}
</script>
<style  scoped>
/* @import '../style/css/mui.min'; */
* {
  margin: 0;
  padding: 0;
  touch-action: pan-y;
  font-family: PingFangSC;
}
.mui-content > .mui-table-view:first-child {
  margin-top: -1px;
}

.todeList {
  margin: 0 auto;
  width: 90%;
  height: 160px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}
.scroller {
  height: 100%;
  background: url(../style/img/bg-search-activity.png);
  background-size: cover;
}
#inner {
  height: auto;
  overflow-y: auto;
}

.leftPic {
  width: 108%;
  height: 96%;
  float: left;
  border-radius: 5px;
  background-size: cover !important;
  margin-left: -4%;
}

.small {
  width: 28%;
  height: 78%;
  margin: 4% 5% 0 5%;
  float: left;
  border-radius: 5px;
  background: rgba(240, 128, 128, 0.6);
}

.rightFont {
  width: 60%;
  height: 80%;
  margin-top: 5%;
  float: left;
}

.title {
  width: 100%;
  min-height: 23%;
  font-size: 13px;
  line-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.more {
  position: absolute;
  top: 270px;
  right: 20px;
  margin: 69px 0px 0 0px;
  height: 30px;
  width: 100px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  color: white;
  text-align: center;
  line-height: 30px;
  font-size: 16px;
}

.color {
  color: yellow;
  min-width: 26px;
  display: inline-block;
  text-align: center;
}

.fontWeight {
  font-size: 18px;
}

.lineHeight {
  line-height: 30px;
}

.last {
  float: right;
  margin-right: 10px;
}

.colorGrey {
  color: grey;
}

.news {
  width: 100%;
  border-radius: 0 0 10px 10px;
  float: left;
  background:rgba(255,255,255,90%);
}

.position {
  color: #cccccc;
}

.maplog {
  float: left;
  height: 10px;
  margin: 3px 3px 0 3px;
  width: 8px;
  background-image: url(../style/img/maplog.png);
  background-size: 100% 100%;
}

.backGrey {
  padding: 2px;
  border-radius: 3px;
  background: rgb(250, 249, 247);
}

.mui-content {
  height: 100%;
  background: white !important;
}

.lineHeight span {
  display: inline-block !important;
  width: 100px !important;
  height: 30px !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pic {
  position: fixed;
  bottom: 40px;
  right: 3%;
  background-image: url(../style/img/30.png);
  background-size: 100% 100%;
  height: 70px;
  width: 70px;
  z-index: 9999;
}
</style>
